package com.yfree.utils;

import android.animation.ValueAnimator;
import android.widget.TextView;

/**
 * Created by Administrator on 2017/8/4.
 */

public class YAnimUtils {
    public static void startTextViewAnim(final TextView textView, final String target) {
        try {
            textView.clearAnimation();
            ValueAnimator mAnimator = ValueAnimator.ofFloat(0, Float.parseFloat(target));
            mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float temp = (int) ((float) animation.getAnimatedValue() * 100) / 100.00f;
                    textView.setText(temp * 100 % 100 == 0 ? String.valueOf((int) temp) : String.valueOf(temp));
                }
            });
            mAnimator.setDuration(2000);
            mAnimator.start();
        } catch (Exception e) {
            textView.setText(target);
        }
    }
}
